﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenericGA.extmath
{
    /// <summary>
    /// An extended Math class for extra mathematical functions.
    /// </summary>
    public class ExtMath
    {

        private ExtMath() { }

        /// <summary>
        /// Find the minimum number of bits needed to represent the given number in binary.
        /// </summary>
        /// <param name="num">The number to represent in binary.</param>
        /// <returns>The number of bits need to represent the given number in binary.</returns>
        public static int MinBits(long num)
        {
            if (num < 0)
            {
                throw new ArgumentException();
            }

            if (num == 0)
            {
                return 1;
            }
            return (int)Math.Floor(Math.Log(num, 2)) + 1;
        }

    }
}
